import { useModel } from "umi";

import AddGateway from "../components/gateway/Add";
import EditGateway from "../components/gateway/Edit";
import SelectDatabaseVersion from "../components/person/SelectDatabaseVersion";

const useHelperGateway = () => {
    const { setModalVisible, setModalTitle, setModalWidth, setModalComponent, setModalStyle } = useModel("global.modal");

    const openAddGatewayModal = async (gateways, reloadData) => {
        setModalTitle("添加个人网关");
        setModalVisible(true);
        setModalWidth(650);
        setModalStyle({ top: 100 });
        setModalComponent(<AddGateway gateways={gateways} reloadData={reloadData} />);
    };

    const openEditGatewayModal = (currGateway, reloadData) => {
        setModalTitle("设置网关备注");
        setModalVisible(true);
        setModalStyle({ top: 100 });
        setModalComponent(<EditGateway gateway={currGateway} reloadData={reloadData} />);
    };

    const openUpdateDatabaseStructureModal = async (reloadData) => {
        setModalTitle("请选择数据库版本");
        setModalVisible(true);
        setModalComponent(<SelectDatabaseVersion reloadData={reloadData} />);
    };

    return { openAddGatewayModal, openEditGatewayModal, openUpdateDatabaseStructureModal };
};

export default useHelperGateway;
